<?php

namespace App\Http\Controllers\Api\v1;

use App\common;
use App\Http\Controllers\Controller;
use App\Logic\SecondaryLogic;
use App\Models\Fang;
use Illuminate\Http\Request;

/**
 * @name wangjinyu
 * Class SecondaryController
 * @package App\Http\Controllers
 * 房源模块控制器
 */
class SecondaryController extends Controller
{
    /**
     * 二手房源信息展示列表
     */
    public function Secondary()
    {
        try {
            $Secondary = SecondaryLogic::Secondary();
            return common::success(20000, $Secondary, '二手房源信息展示成功');
        } catch (\Exception $exception) {
            return common::fail('', "", $exception->getMessage());
        }
    }

    /**
     * 数据库信息同步存入redis
     * @return array|false|string
     */
    public function redisSecondaryList(){
        try {
            $Secondary = SecondaryLogic::redisSecondaryList();
            return common::success(20000, $Secondary, '二手房源信息成功存入redis');
        } catch (\Exception $exception) {
            return common::fail('', "", $exception->getMessage());
        }
    }
    /**
     * 二手房源信息添加
     */
    public function SecondaryAdd(Request $request)
    {
        try {
            $SecondaryAdd = SecondaryLogic::SecondaryAdd($request);
            return common::success(20000, $SecondaryAdd, '二手房源信息添加成功');
        } catch (\Exception $exception) {
            return common::fail('', "", $exception->getMessage());
        }
    }

    /**
     * 二手房源信息删除
     */
    public function SecondaryDel(Request $request)
    {
        try {
            $fangId = $request->get('id');
            $secondaryMessage = SecondaryLogic::SecondaryDel($fangId);
            return common::success(20000, $secondaryMessage, '二手房源信息删除成功');
        } catch (\Exception $exception) {
            return common::fail('', "", $exception->getMessage());
        }
    }

    /**
     * 二手房源信息查找
     */
    public function SecondarySeek(Request $request)
    {
        try {
            $keyword = $request->get('keyword');
            $SecondaryMessage = SecondaryLogic::SecondarySeek($keyword);
            return common::success(20000, $SecondaryMessage, '二手房源信息搜索成功');
        } catch (\Exception $exception) {
            return common::fail('', "", $exception->getMessage());
        }
    }

    /**
     * 二手房源详情
     */
    public function SecondaryDetails(Request $request)
    {
        try {
            $fangId = $request->get('id');
            $SecondaryMessage = SecondaryLogic::SecondaryDetails($fangId);
            return common::success(20000, $SecondaryMessage, '二手房源详情展示成功');
        } catch (\Exception $exception) {
            return common::fail('', "", $exception->getMessage());
        }
    }

    /**
     * 二手房源修改
     */
    public function SecondaryUpdated(Request $request)
    {
        try {
            $SecondaryMessageUpdated = $request->post();
            $SecondaryAdd = SecondaryLogic::SecondaryUpdated($SecondaryMessageUpdated);
            return common::success(20000, $SecondaryAdd, '二手房源信息修改成功');
        } catch (\Exception $exception) {
            return common::fail('', "", $exception->getMessage());
        }
    }

    /**
     * 二手房源es搜索
     */
    public function SecondarySearch(Request $request)
    {
        try {
            $keyword = $request->get('keyword');
            $SecondaryMessage = SecondaryLogic::SecondarySearch($keyword);
            return common::success(20000, $SecondaryMessage, '二手房源es搜索成功');
        } catch (\Exception $exception) {
            return common::fail('', "", $exception->getMessage());
        }
    }
}
